package net.sf.midollo.task;

public class Task implements Runnable {

	protected final Object[] args;
	protected Object result;
	protected Throwable error;

	public Task(Object[] args) {
		this.args = args;
	}

	public Object getResult() {
		return this.result;
	}

	public Throwable getError() {
		return this.error;
	}

	public void run() {
		try {
			this.result = execute(this.args);
			this.error = null;
		} catch (Throwable error) {
			this.error = error;
		} finally {
			completed();
		}
	}

	protected Object execute(Object[] args) throws Throwable {
		return null;
	}

	protected void completed() {
	}
}
